package jmm;

import java.util.concurrent.TimeUnit;

/**
 * @author ：黄淼淳
 * @date ：2021/12/17 18:19
 * @description：
 */
public class Demo {
    public static void main(String[] args) {
        Resourse resourse = new Resourse();
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t开始运行了。。。");
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            resourse.add();
            System.out.println(Thread.currentThread().getName() + "\t将number改为了：" + resourse.number);
        }, "A").start();
        while (resourse.number==10){}
        System.out.println("main线程当前number值为："+resourse.number);
    }
}


class Resourse {
    volatile int number = 10;

    void add() {
        number += 10;
    }
}